package protocol;

import java.nio.ByteBuffer;

import outboxHandler.OutboxHandler;

public class User {

private String channel;
private String nick;
private String user;
private boolean quit;

/** ########################################################################## */
private OutboxHandler outboxHandler;

/** ########################################################################## */
public User(String welcomeMessage) {			//////////////////////////// MAYBE NO NEED FOR PARAM STRING HERE!!
	
	this.channel = null;
	this.nick = null;
	this.user = null;
}

/** ########################################################################## */
public void register(OutboxHandler connector)
{
	this.outboxHandler=connector;
}

public String getChannel() {
	if(channel!=null)
		return new String(channel);
	else
		return null;
}

public void setChannel(String channel) {
	if(channel!=null)
	this.channel = new String(channel);
	else
		this.channel=null;
		
}

public String getNick() {
	if(nick!=null)
		return new String(nick);
	else
		return null;
}

public void setNick(String nick) {
	this.nick = new String(nick);
}

public String getUser() {
	if(user!=null)
		return new String(user);
	else
		return null;
}

public void setUser(String user) {
	this.user = new String(user);
}

public void Quit() {
	quit=true;
	
}

public boolean shouldQuit()
{
	return quit;
}

/** ########################################################################## */
/*
public String getFromOutbox(){
	StringBuilder ans = outbox.delete(0, outbox.length());
	return ans.substring(0);
}
*/

/** ########################################################################## */
public void toOutbox(String message){

	byte bytedMessage[]=message.getBytes();
	ByteBuffer buffedMessage=ByteBuffer.allocate(bytedMessage.length);
	buffedMessage=ByteBuffer.wrap(bytedMessage);
	outboxHandler.updateOutBox(buffedMessage);
	System.out.println("message moved to outbox of user ");
}

/** ########################################################################## */
public String toString()
{
	return getNick();
}

}
